package com.test45_JUC;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * 使用LockSupport类实现暂停与恢复执行
 */
public class Demo10_LockSupport {
    public static String msg = null;

    public static void main(String[] args) {
        Thread mainThread = Thread.currentThread();
        new Thread(() -> {  // 创建子线程，修改msg的属性内容
            System.out.printf("【%s】准备进行数据的处理操作%n", Thread.currentThread().getName());
            try {
                TimeUnit.SECONDS.sleep(2);
                msg = "沐言科技：www.yootk.com/resources";   // 修改数据内容
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                LockSupport.unpark(mainThread);  // 恢复主线程
            }
        }, "子线程").start();
        LockSupport.park(mainThread);   // 挂起主线程
        System.out.println("【主线程】得到最终处理的结果：" + msg);
    }
}
